// lib/pages/leadership_care.dart
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:portal_website/pages/common_header.dart';

import 'package:flutter/material.dart';
import 'package:portal_website/tool/image_network.dart';
import 'package:webview_flutter/webview_flutter.dart';

class LeaderCarePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final navItems = [
      {'name': '首页', 'route': '/'},
      {'name': '新闻资讯', 'route': '/'},
      {'name': '领导关怀', 'route': '/'},
      {'name': '基地概况', 'route': '/'},
      {'name': '联系我们', 'route': '/'},
    ];
    return Scaffold(
      backgroundColor: Color(0xFFF5F9FF),
      body: SingleChildScrollView(
        child: Container(
          width: double.infinity,
          padding: EdgeInsets.only(top: 10),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              // 主要内容
              Padding(
                padding: EdgeInsets.symmetric(vertical: 15, horizontal: 10),
                child: Text(
                  '首页 > 领导关怀',
                  style: TextStyle(
                    color: Color(0xFF666666),
                    fontSize: 14,
                  ),
                ),
              ),
              PageTitle(
                title: "领导关怀",
                subtitle: "各级领导对濮阳人工智能创新应用示范基地的关心指导和支持",
              ),

              // 领导考察部分
              _buildLeaderSection(
                title: '领导考察',
                description: '濮阳人工智能创新应用示范基地的建设和发展得到了各级领导的高度重视和亲切关怀。',
                child: Column(
                  children: [
                    _buildVisitItem(
                      title: '省委书记张伟一行莅临基地考察指导',
                      date: '2025年7月15日',
                      content: [
                        '7月15日，省委书记张伟率领省委省政府相关部门负责人莅临濮阳人工智能创新应用示范基地考察指导工作。张书记详细了解了基地建设运营情况，对基地在推动区域创新发展方面取得的成绩给予充分肯定。',
                        '考察期间，张书记参观了基地展示中心、创新实验室和入驻企业办公区，与基地管理人员和入驻企业代表进行了深入交流，并就下一步发展方向提出了指导意见。',
                        '张书记强调，要充分发挥人工智能在产业转型升级中的引领作用，加快技术研发和成果转化，为全省高质量发展提供有力支撑。'
                      ],
                      imageUrl: '',
                      gallery: [
                        {'url': '', 'caption': '张书记听取基地建设情况汇报'},
                        {'url': '', 'caption': '张书记参观创新实验室'},
                        {'url': '', 'caption': '张书记与入驻企业代表交流'},
                      ],
                      hasVideo: true,
                      mediaReports: [
                        {
                          'imageUrl': '',
                          'title': '省委书记张伟考察濮阳人工智能基地',
                          'source': '河南日报 | 2025年7月16日',
                          'desc':
                              '河南日报头版报道了省委书记张伟考察濮阳人工智能创新应用示范基地的相关情况，重点介绍了基地在推动区域创新发展方面的工作成效。'
                        },
                        {
                          'imageUrl': '',
                          'title': '张伟：打造人工智能创新高地',
                          'source': '河南电视台 | 2025年7月15日',
                          'desc':
                              '河南电视台新闻联播报道了省委书记张伟考察濮阳人工智能基地的详细情况，并播出了张书记的重要讲话。'
                        },
                      ],
                    ),
                    _buildVisitItem(
                      title: '省长李强调研基地建设工作',
                      date: '2025年6月10日',
                      content: [
                        '6月10日，省长李强率省直有关部门负责人到濮阳人工智能创新应用示范基地调研建设工作。李强省长实地查看了基地建设进展，详细了解基地规划布局、功能定位和运营模式。',
                        '调研中，李强省长强调，要高标准推进基地建设，聚焦人工智能核心技术攻关和应用场景创新，打造具有区域影响力的创新平台。要充分发挥基地的辐射带动作用，促进人工智能与实体经济深度融合。',
                        '李强省长还现场办公，协调解决基地建设过程中遇到的困难和问题，要求有关部门加大支持力度，确保基地早日建成投用。'
                      ],
                      imageUrl: '',
                      gallery: [
                        {'url': '', 'caption': '李强省长听取基地规划汇报'},
                        {'url': '', 'caption': '李强省长查看建设工地'},
                        {'url': '', 'caption': '李强省长与建设者交流'},
                      ],
                      hasVideo: false,
                      mediaReports: [
                        {
                          'imageUrl': '',
                          'title': '李强调研濮阳人工智能基地建设',
                          'source': '河南日报 | 2025年6月11日',
                          'desc': '河南日报报道了省长李强调研濮阳人工智能创新应用示范基地建设工作的相关情况。'
                        },
                      ],
                    ),
                    _buildVisitItem(
                      title: '市委书记王刚检查基地安全生产工作',
                      date: '2025年5月8日',
                      content: [
                        '5月8日，市委书记王刚带队到濮阳人工智能创新应用示范基地检查安全生产工作。王刚书记实地查看了基地施工现场、消防设施和安全管理制度落实情况。',
                        '王刚书记强调，要牢固树立安全发展理念，严格落实安全生产责任制，确保基地建设安全有序推进。要加强对入驻企业的安全培训和管理，筑牢安全生产防线。',
                        '检查中，王刚书记还详细了解了基地建设进展和招商情况，要求加快建设进度，确保按期投入使用。'
                      ],
                      imageUrl: '',
                      gallery: [
                        {'url': '', 'caption': '王刚书记检查施工现场'},
                        {'url': '', 'caption': '王刚书记查看消防设施'},
                      ],
                      hasVideo: false,
                      mediaReports: [],
                    ),
                  ],
                ),
              ),

              // 页脚
              CommonFooter(
                links: [
                  {'name': '关于我们'},
                  {'name': '新闻动态'},
                  {'name': '入驻申请'},
                  {'name': '人才招聘'},
                  {'name': '联系我们'},
                ],
                copyright: '© 2025 濮阳人工智能创新应用示范基地 版权所有',
                contactInfo:
                    '地址：河南省濮阳市高新技术开发区人工智能产业园 | 电话：0393-1234567 | 邮箱：info@puyang-ai.com',
              ),
            ],
          ),
        ),
      ),
    );
  }

  // 构建导航项
  Widget _buildNavItem(String text) {
    return Padding(
      padding: EdgeInsets.only(left: 25),
      child: Text(
        text,
        style: TextStyle(
          color: Colors.white,
          fontSize: 16,
        ),
      ),
    );
  }

  // 构建领导关怀区块
  Widget _buildLeaderSection({
    required String title,
    String? description,
    required Widget child,
  }) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8),
        boxShadow: [
          BoxShadow(
            color: Colors.black12,
            blurRadius: 3,
            spreadRadius: 1,
            offset: Offset(0, 3),
          ),
        ],
      ),
      padding: EdgeInsets.all(40),
      margin: EdgeInsets.only(bottom: 40),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // 区块标题
          Container(
            margin: EdgeInsets.only(bottom: 30),
            padding: EdgeInsets.only(bottom: 15),
            decoration: BoxDecoration(
              border: Border(
                bottom: BorderSide(
                  color: Color(0xFFF0F0F0),
                  width: 2,
                ),
              ),
            ),
            child: Stack(
              children: [
                Text(
                  title,
                  style: TextStyle(
                    color: Color(0xFF1E5799),
                    fontSize: 24,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                Positioned(
                  bottom: -2,
                  left: 0,
                  child: Container(
                    width: 80,
                    height: 2,
                    color: Color(0xFF207CCA),
                  ),
                ),
              ],
            ),
          ),

          // 描述（可选）
          if (description != null)
            Padding(
              padding: EdgeInsets.only(bottom: 30),
              child: Text(
                description,
                style: TextStyle(
                  color: Color(0xFF333333),
                  fontSize: 16,
                  height: 1.6,
                ),
              ),
            ),

          // 子内容
          child,
        ],
      ),
    );
  }

  // 构建考察项目
  Widget _buildVisitItem({
    required String title,
    required String date,
    required List<String> content,
    required String imageUrl,
    required List<Map<String, String>> gallery,
    required bool hasVideo,
    required List<Map<String, String>> mediaReports,
  }) {
    return Container(
      margin: EdgeInsets.only(bottom: 50),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // 标题和日期
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                title,
                style: TextStyle(
                  color: Color(0xFF1E5799),
                  fontSize: 22,
                  fontWeight: FontWeight.bold,
                ),
              ),
              Text(
                date,
                style: TextStyle(
                  color: Color(0xFF207CCA),
                  fontWeight: FontWeight.bold,
                  fontSize: 16,
                ),
              ),
            ],
          ),
          SizedBox(height: 20),

          // 内容和图片
          MediaQuery.of(Get.context!).size.width < 768
              ? Column(
                  children: [
                    _buildVisitContent(content),
                    SizedBox(height: 20),
                    ClipRRect(
                      borderRadius: BorderRadius.circular(8),
                      child: ImageNetwork(
                        imageUrl,
                        width: double.infinity,
                        height: 250,
                        fit: BoxFit.cover,
                      ),
                    ),
                  ],
                )
              : Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Expanded(
                      child: _buildVisitContent(content),
                    ),
                    SizedBox(width: 30),
                    ClipRRect(
                      borderRadius: BorderRadius.circular(8),
                      child: ImageNetwork(
                        imageUrl,
                        width: 400,
                        height: 250,
                        fit: BoxFit.cover,
                      ),
                    ),
                  ],
                ),
          SizedBox(height: 30),

          // 考察照片
          Text(
            '考察照片',
            style: TextStyle(
              fontSize: 18,
              fontWeight: FontWeight.bold,
              color: Color(0xFF333333),
            ),
          ),
          SizedBox(height: 20),

          // 照片画廊
          GridView.count(
            shrinkWrap: true,
            physics: NeverScrollableScrollPhysics(),
            crossAxisCount:
                MediaQuery.of(Get.context!).size.width < 768 ? 1 : 3,
            crossAxisSpacing: 20,
            mainAxisSpacing: 20,
            childAspectRatio: 300 / 230,
            children: gallery.map((item) {
              return Container(
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(8),
                    color: Colors.white,
                    boxShadow: [
                      BoxShadow(
                        color: Colors.black12,
                        blurRadius: 5,
                        spreadRadius: 1,
                        offset: Offset(0, 5),
                      ),
                    ]),
                child: Column(
                  children: [
                    ImageNetwork(
                      item['url'] ?? "",
                      width: double.infinity,
                      height: 200,
                      fit: BoxFit.cover,
                    ),
                    Container(
                      padding: EdgeInsets.all(15),
                      color: Colors.white,
                      child: Text(
                        item['caption']!,
                        textAlign: TextAlign.center,
                        style: TextStyle(
                          color: Color(0xFF666666),
                          fontSize: 14,
                        ),
                      ),
                    ),
                  ],
                ),
              );
            }).toList(),
          ),
          SizedBox(height: 30),

          // 考察视频（如果有）
          if (hasVideo) ...[
            Text(
              '考察视频',
              style: TextStyle(
                fontSize: 18,
                fontWeight: FontWeight.bold,
                color: Color(0xFF333333),
              ),
            ),
            SizedBox(height: 20),
            Container(
              height: 300,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(8),
                boxShadow: [
                  BoxShadow(
                    color: Colors.black12,
                    blurRadius: 5,
                    spreadRadius: 1,
                    offset: Offset(0, 5),
                  ),
                ],
              ),
              // child: WebView(
              //   initialUrl: 'https://www.youtube.com/embed/example1',
              //   javascriptMode: JavascriptMode.unrestricted,
              // ),
            ),
            SizedBox(height: 30),
          ],

          // 媒体报道（如果有）
          if (mediaReports.isNotEmpty) ...[
            Text(
              '媒体报道',
              style: TextStyle(
                fontSize: 18,
                fontWeight: FontWeight.bold,
                color: Color(0xFF333333),
              ),
            ),
            SizedBox(height: 20),
            Column(
              children: mediaReports.map((report) {
                return Container(
                  margin: EdgeInsets.only(bottom: 30),
                  decoration: BoxDecoration(
                    color: Color(0xFFF9FBFF),
                    borderRadius: BorderRadius.circular(8),
                    // overflow: Clip.antiAlias,
                  ),
                  child: MediaQuery.of(Get.context!).size.width < 768
                      ? Column(
                          children: [
                            ImageNetwork(
                              report['imageUrl']!,
                              width: double.infinity,
                              height: 200,
                              fit: BoxFit.cover,
                            ),
                            Container(
                              padding: EdgeInsets.all(20),
                              child: _buildMediaContent(report),
                            ),
                          ],
                        )
                      : Row(
                          children: [
                            ImageNetwork(
                              report['imageUrl']!,
                              width: 300,
                              height: 200,
                              fit: BoxFit.cover,
                            ),
                            Expanded(
                              child: Container(
                                padding: EdgeInsets.all(20),
                                child: _buildMediaContent(report),
                              ),
                            ),
                          ],
                        ),
                );
              }).toList(),
            ),
          ],
        ],
      ),
    );
  }

  // 构建考察内容文本
  Widget _buildVisitContent(List<String> paragraphs) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: paragraphs
          .map((para) => Padding(
                padding: EdgeInsets.only(bottom: 16),
                child: Text(
                  para,
                  style: TextStyle(
                    color: Color(0xFF555555),
                    fontSize: 16,
                    height: 1.8,
                  ),
                ),
              ))
          .toList(),
    );
  }

  // 构建媒体报道内容
  Widget _buildMediaContent(Map<String, String> report) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          report['title']!,
          style: TextStyle(
            color: Color(0xFF1E5799),
            fontSize: 18,
            fontWeight: FontWeight.bold,
          ),
        ),
        SizedBox(height: 10),
        Text(
          report['source']!,
          style: TextStyle(
            color: Color(0xFF666666),
            fontSize: 14,
          ),
        ),
        SizedBox(height: 10),
        Text(
          report['desc']!,
          style: TextStyle(
            color: Color(0xFF555555),
            fontSize: 15,
            height: 1.8,
          ),
        ),
        SizedBox(height: 15),
        TextButton(
          onPressed: () {},
          style: TextButton.styleFrom(
            padding: EdgeInsets.zero,
            minimumSize: Size(50, 30),
            tapTargetSize: MaterialTapTargetSize.shrinkWrap,
          ),
          child: Text(
            '查看报道 →',
            style: TextStyle(
              color: Color(0xFF207CCA),
              fontWeight: FontWeight.bold,
              fontSize: 14,
            ),
          ),
        ),
      ],
    );
  }

  // 构建页脚
  Widget _buildFooter(List<String> links, String copyright, String contact) {
    return Container(
      decoration: BoxDecoration(
        color: Color(0xFF1A1A2E),
        borderRadius: BorderRadius.circular(8),
      ),
      padding: EdgeInsets.all(40),
      margin: EdgeInsets.only(top: 50),
      child: Column(
        children: [
          // 链接
          Wrap(
            spacing: 40,
            runSpacing: 10,
            children: links.map((link) {
              return TextButton(
                onPressed: () {},
                style: TextButton.styleFrom(
                  padding: EdgeInsets.zero,
                  minimumSize: Size(50, 30),
                  tapTargetSize: MaterialTapTargetSize.shrinkWrap,
                ),
                child: Text(
                  link,
                  style: TextStyle(
                    color: Color(0xFFA8B2D1),
                    fontSize: 16,
                  ),
                ),
              );
            }).toList(),
          ),
          SizedBox(height: 20),
          // 版权信息
          Text(
            copyright,
            style: TextStyle(
              color: Colors.white,
              fontSize: 16,
              height: 1.6,
            ),
          ),
          SizedBox(height: 10),
          // 联系信息
          Text(
            contact,
            style: TextStyle(
              color: Colors.white,
              fontSize: 14,
              height: 1.6,
            ),
            textAlign: TextAlign.center,
          ),
        ],
      ),
    );
  }
}

// 领导考察组件
class LeadershipVisit extends StatelessWidget {
  final Map<String, dynamic> visit;

  const LeadershipVisit({super.key, required this.visit});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(bottom: 50),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            visit['title'],
            style: const TextStyle(
              fontSize: 22,
              color: Color(0xFF1e5799),
              fontWeight: FontWeight.bold,
            ),
          ),
          const SizedBox(height: 10),
          Text(
            visit['date'],
            style: const TextStyle(
              color: Color(0xFF207cca),
              fontWeight: FontWeight.bold,
              fontSize: 16,
            ),
          ),
          const SizedBox(height: 20),
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Expanded(
                child: Text(
                  visit['description'],
                  style: const TextStyle(
                    fontSize: 16,
                    color: Color(0xFF555555),
                    height: 1.8,
                  ),
                ),
              ),
              const SizedBox(width: 30),
              ImageNetwork(
                visit['imageUrl'],
                width: 400,
                height: 250,
                fit: BoxFit.cover,
                // borderRadius: BorderRadius.circular(8),
              ),
            ],
          ),
          const SizedBox(height: 30),
          const Text(
            '考察照片',
            style: TextStyle(
              fontSize: 18,
              color: Color(0xFF1e5799),
              fontWeight: FontWeight.bold,
              // margin: EdgeInsets.only(bottom: 20),
            ),
          ),
          GridView.count(
            crossAxisCount: 3,
            crossAxisSpacing: 20,
            mainAxisSpacing: 20,
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            childAspectRatio: 300 / 250,
            children: (visit['gallery'] as List<Map<String, String>>)
                .map((item) => Container(
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(8),
                        boxShadow: [
                          BoxShadow(
                            color: Colors.black12,
                            blurRadius: 5,
                            spreadRadius: 1,
                          ),
                        ],
                      ),
                      child: Column(
                        children: [
                          ImageNetwork(
                            item['imageUrl']!,
                            width: double.infinity,
                            height: 200,
                            fit: BoxFit.cover,
                          ),
                          Container(
                            padding: const EdgeInsets.all(15),
                            color: Colors.white,
                            child: Text(
                              item['caption']!,
                              textAlign: TextAlign.center,
                              style: const TextStyle(
                                color: Color(0xFF666666),
                                fontSize: 14,
                              ),
                            ),
                          ),
                        ],
                      ),
                    ))
                .toList(),
          ),
          const SizedBox(height: 30),
          // const Text(
          //   '考察视频',
          //   style: TextStyle(
          //     fontSize: 18,
          //     color: Color(0xFF1e5799),
          //     fontWeight: FontWeight.bold,
          //     // margin: EdgeInsets.only(bottom: 20),
          //   ),
          // ),
          // Container(
          //   padding: const EdgeInsets.all(20),
          //   decoration: BoxDecoration(
          //     borderRadius: BorderRadius.circular(8),
          //     boxShadow: [
          //       BoxShadow(
          //         color: Colors.black12,
          //         blurRadius: 5,
          //         spreadRadius: 1,
          //       ),
          //     ],
          //   ),
          //   child: AspectRatio(
          //     aspectRatio: 16 / 9,
          //     child: Container(
          //       color: Colors.grey[200],
          //       child: const Center(
          //         child: Text('视频播放器'),
          //       ),
          //     ),
          //   ),
          // ),
          // const SizedBox(height: 30),
          const Text(
            '媒体报道',
            style: TextStyle(
              fontSize: 18,
              color: Color(0xFF1e5799),
              fontWeight: FontWeight.bold,
              // margin: EdgeInsets.only(bottom: 20),
            ),
          ),
          Container(
            margin: const EdgeInsets.only(bottom: 30),
            decoration: BoxDecoration(
              color: const Color(0xFFf9fbff),
              borderRadius: BorderRadius.circular(8),
            ),
            child: Row(
              children: [
                ImageNetwork(
                  visit['media']['imageUrl'],
                  width: 300,
                  height: 200,
                  fit: BoxFit.cover,
                ),
                Expanded(
                  child: Container(
                    padding: const EdgeInsets.all(20),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          visit['media']['title'],
                          style: const TextStyle(
                            fontSize: 18,
                            color: Color(0xFF1e5799),
                            fontWeight: FontWeight.bold,
                            // margin: EdgeInsets.only(bottom: 10),
                          ),
                        ),
                        Text(
                          visit['media']['source'],
                          style: const TextStyle(
                            color: Color(0xFF666666),
                            fontSize: 14,
                            // margin: EdgeInsets.only(bottom: 10),
                          ),
                        ),
                        Text(
                          visit['media']['description'],
                          style: const TextStyle(
                            color: Color(0xFF555555),
                            fontSize: 15,
                            height: 1.8,
                          ),
                        ),
                        const SizedBox(height: 15),
                        InkWell(
                          onTap: () {},
                          child: const Text(
                            '查看报道 →',
                            style: TextStyle(
                              color: Color(0xFF207cca),
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
